var BSTMG = BSTMG || {};
BSTMG.payByothersManager = {
	init: function(){
		var that = this;
		//分页功能
		that.selectPayByothersList("");
		//根据条件查询
		that.payWayId();
	},
	selectPayByothersList: function(payWayId){
		var url = "/sysAdmin/accountMoney/payByOthersList/search?payWayId="+payWayId;
		BSTMG.common.hjhPages(url,function(data){
			var userList = data.userList;
	
			var recoveryAccount = data.recoveryAccount;
			$('#recoveryAccount').text(parseFloat(recoveryAccount).toFixed(2));
			
			var $tbody = $("#payByOthersList tbody");
			var $tr = '';
			if(userList.length > 0) {
				for(var i=0;i<userList.length;i++){
					var userInfo = userList[i];
					var loginNum = setLoginNum(userInfo);
					var dealMoney = setDealMoney(userInfo);
					var payWayId = setPayWayId(userInfo);
					$tr += '<tr class="odd">';
					$tr += '<td>'+(i+1)+'</td>';
					$tr += '<td>'+BSTMG.tools.checkNull(loginNum)+'</td>';
					$tr += '<td>'+BSTMG.tools.checkNull(parseFloat(dealMoney).toFixed(2))+'</td>';
					$tr += '<td>'+BSTMG.tools.checkNull(toDate(userInfo.createTime,"yyyy-MM-dd hh:mm:ss"))+'</td>';
					$tr += '<td>'+BSTMG.tools.checkNull(payWayId)+'</td>';
					$tr += '<td><a type="button" class="btn btn-primary" href="/sysAdmin/accountMoney/payByOthersDetail/'+userInfo.cashflowNum+'">详细信息</a></td>';
					$tr += '</tr>';
				}
				$tbody.html($tr);
			}else {
				var $tr = '<tr class="odd"><td colspan="6">暂无数据！</td></tr>';
				$tbody.html($tr);
			}
		});
	},
	payWayId : function(){
		$('#payWayId').on('change',function(){
			var payWayId = $('#payWayId').val();
			//applyState = $('#applyState').val();
			BSTMG.payByothersManager.selectPayByothersList(payWayId);
		})
	},
}

$(function(){
	BSTMG.payByothersManager.init();
});
//设置登陆账号
function setLoginNum(userInfo){
	if(userInfo.userEmail != "" && userInfo.userEmail != null){
		return userInfo.userEmail;
	}else if(userInfo.userTel != "" && userInfo.userTel != null){
		return userInfo.userTel;
	}else{
		return "";
	}
}
//设置交易金额
function setDealMoney(userInfo){
	if(userInfo.incomeMoney==0.00||userInfo.incomeMoney==null||userInfo.incomeMoney==""){
		return userInfo.disburseMoney;
	}else{
		return userInfo.incomeMoney;
	}
}
//设置支付方式
function setPayWayId(userInfo){
	if(userInfo.payWayId == 1){
		return "支付宝支付";
	}else if(userInfo.payWayId == 2){
		return "账户余额支付";
	}else if(userInfo.payWayId == 3){
		return "银联支付";
	}else if(userInfo.payWayId == 4){
		return "线下支付";
	}else{
		return "";
	}
}



